#include <iostream>
#include <vector>
using namespace std;
class Solution {
private:
    vector<string> ret;
    void dfs(string ans,int num,int left,int right)
    {
        if(left == num && left == right)
        {
            ret.emplace_back(ans);
            return;
        }
        if(left < num) dfs(ans+"(",num,left+1,right);
        if(right < num && right < left) dfs(ans+")",num,left,right+1);
    }
public:
    vector<string> generateParenthesis(int n) 
    {
        dfs("",n,0,0);
        return ret;
    }
};

int main()
{
    Solution sol;
    vector<string> res = sol.generateParenthesis(3);
    for(auto item : res)
        cout << item << endl;
    return 0;
}